//
//  SQRechargeCell.m
//  pai
//
//  Created by pro on 14-12-1.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQRechargeCell.h"
#import "Global.h"

@implementation SQRechargeCell

+(SQRechargeCell*)initmyview
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"SQRechargeCell" owner:nil options:nil];
    
    return [nibView objectAtIndex:0];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
-(void)initPayType
{
    self.accountLabel.text = [Global instance].userinfo.username;
    self.mobileLabel.text = [Global instance].userinfo.mobile;
    self.wechatpayView.hidden = YES;
    self.bankpayView.hidden = YES;
    //self.alipayView.hidden = YES;
    [self initcheckbox:self.alipayView selected:YES];
    //[self initcheckbox:self.wechatpayView selected:YES];
    self.paytype = @"alipay";
}

-(void)initcheckbox:(UIView*)cell selected:(BOOL)flag
{
    UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect checkboxRect = CGRectMake(258,8,30,30);
    [checkbox setFrame:checkboxRect];
    
    [checkbox setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
    [checkbox setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateSelected];
    checkbox.selected = flag;
//    [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:checkbox];
}
-(void)checkboxClick:(UIButton *)btn
{
    [self initbtn];
    btn.selected = !btn.selected;
}
-(void)initbtn
{
    
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    [super touchesBegan:touches withEvent:event];
}
- (IBAction)doActionClickMoneyBtn:(id)sender {
    UIButton *button = (UIButton *)sender;
    NSString* str = [button.titleLabel text];
    NSString* money = [str substringToIndex:str.length -1];
    self.moneyLabel.text = money;
    //NSLog(@"%@",[sender.titleLabel text]);
}

- (IBAction)doActionPay:(id)sender {
    float num = [self.moneyLabel.text floatValue];
//    if (num < 1) {
//        UIAlertView* alterView = [[UIAlertView alloc]initWithTitle:nil message:@"充值金额有误！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
//        [alterView show];
//        return;
//    }else{
        [self.delegate dorecharge:self.moneyLabel.text withType:@"alipay"];
    //}
}
@end
